﻿
using System.Collections.Generic;

class ShortTermMemory
{
    private const int MemorySize = 3;               //Max lines to keep in memory
    private string _humanName;                      //What does is the human named?
    private string _myName;                         //What is my own name?

    //private Time topicstarttime;           //When we started talking about this topic

    private readonly LinkedList<string> _playerSaid;
    private readonly LinkedList<string> _previousTopics;
    public TalkMode Mode { get; set; }

    public string CurrentTopic { get; set; }

    public enum TalkMode
    {
        Greeting,
        Talking,
        Goodbye,
        MasterCommand
    }

    public ShortTermMemory()
    {
        _previousTopics = new LinkedList<string>();
        _playerSaid = new LinkedList<string>();
        Clear();
    }


    //This keeps track of what the player has previously said
    public void UpdateMemory(string playerSaid)
    {
        _playerSaid.AddFirst(playerSaid);
        if (_playerSaid.Count > MemorySize) _playerSaid.RemoveLast();
    }

    public void Clear()
    {
        _myName = "KID Junior";
        _humanName = "\"- I forgot your name -\"";
        Mode = TalkMode.Greeting;
        _playerSaid.Clear();
        _previousTopics.Clear();
    }

    public string GetMyName()
    {
        return _myName;
    }

    public string GetHumanName()
    {
        return _humanName;
    }

    public void SetHumanName(string name)
    {
        _humanName = name;
    }

    public bool HumanIsRepeating(string topic)
    {
        return _playerSaid.Contains(topic);
    }

    public string GetLastHumanString()
    {
        if (_playerSaid.Count == 0) return "LAST_THING_PLAYER_SAID";
        return _playerSaid.First.Value;
    }

    public bool IsPreviousTopic(string topic)
    {
        return CurrentTopic == topic || _previousTopics.Contains(topic);
    }
}